const Router = require("koa-router");
const router = new Router({ prefix: "/get/" });
const { getFile } = require("../utils/index");

// 读取文件
router.get(":fileName", (ctx, next) => {
  try {
    ctx.response.status = 200; // 设置响应状态码
    ctx.response.type = "application/json"; // 设置响应类型
    ctx.body = {
      status: 200,
      success: true,
      message: "请求成功",
      data: getFile(`../data/${ctx.params.fileName}.json`),
    };
  } catch (error) {
    ctx.body = {
      status: 200,
      success: false,
      message: "没有该配置文件",
    };
  }
});

module.exports = router;
